package cn.group.controller;


import cn.group.service.GoodSalesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.qo.GoodSales;
import utils.BaseController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "统计商品销量")
@Controller
@RequestMapping(value = "/goodSales", produces = "text/html;charset=utf-8")
public class GoodSalesController extends BaseController {

    @Autowired
    private GoodSalesService goodSalesService;

    @ApiOperation("展示销量")
    @RequestMapping(value = "showGoodSales.do")
    @ResponseBody
    public String showGoodSales(HttpServletResponse resp) {
        List<GoodSales> goodSalesList=goodSalesService.showGoodSales();
        if (null==goodSalesList){
            String errorMsg="展示失败";
          return   writerErrorResult(errorMsg,resp);
        }
        return writerSuccessResult(goodSalesList,resp);
    }

    @ApiOperation("修改购买量")
    @RequestMapping(value = "updateSalesPurchased.do")
    @ResponseBody
    public String updateSalesPurchased(@RequestBody GoodSales goodSales,HttpServletResponse resp){
        System.out.println("修改购买量"+goodSales);
        int i=goodSalesService.updatePurchased(goodSales);
        if (i!=1){
            String errorMsg="修改失败";
          return   writerErrorResult(errorMsg,resp);
        }
        return writerSuccessResult(i,resp);
    }
}
